import React, { Component } from 'react';
import BaseTableComp from './BaseTableComp';
import { WeaTools } from 'ecCom';

/*
topTitle WeaTop的title
topBtns  WeaTop的btns

tabKey  选项卡的主键
tabUrl  获取tab数据的接口
tabParams 获取tab数据的参数
searchFormUrl 获取高级搜索的接口
searchParams 获取高级搜索的参数
baseSearchName 基础搜索的name
selectedTabKey 直接设置tab页签的selectedTabKey

tableUrl 获取列表数据的接口
tableParams 获取列表数据的参数
getColumns  需要自定义渲染的方法
onOperatesClick 操作
*/

export default class BaseOdocTypeComp extends Component {
  constructor(props) {
    super(props);
    this.selectedTabKey = (props.location && props.location.query.selectedTabKey) || '0';
  }

  render() {
    return (
      <BaseTableComp ecId={`${this && this.props && this.props.ecId || ''}_BaseTableComp@gwo101`}
        getColumns={this.getColumns}
        tabKey="flowtype"
        tabUrl="/api/odoc/odocNewTodoList/getTodoCount"
        tableUrl="/api/odoc/odocNewTodoList/getCustomReqList"
        ref={'baseTableComp'}
        onOperatesClick={(record, index) => this.onOperatesClick(record, index)}
        selectedTabKey={this.selectedTabKey}
        tableListNumber={5}
        needTop={false}
        weaTableProps={{
          pagination: false,
        }}
        {...this.props}
      />
    );
  }

  getTodo = (requestid, returntdid) => {
    jQuery.ajax({
      url: `/api/odoc/odocNewTodoList/getOperatorPersons?requestid=${requestid}&persontype=0`,
      type: 'post',
      dataType: 'json',
      success(res) {
        try {
          jQuery(`#${returntdid}`).html(res.info);
          jQuery(`#${returntdid}`).parent().attr('title', res.info);
        } catch (e) { }
      },
    });
  }

  getDoing = (requestid, returntdid) => {
    jQuery.ajax({
      url: `/api/odoc/odocNewTodoList/getOperatorPersons?requestid=${requestid}&persontype=1`,
      type: 'post',
      dataType: 'json',
      success(res) {
        try {
          jQuery(`#${returntdid}`).html(res.info);
          jQuery(`#${returntdid}`).parent().attr('title', res.info);
        } catch (e) { }
      },
    });
  }

  doPrintRequest = (requestid, beluserid, otherpara = '') => {
    const printurl = '/workflow/request/PrintRequestForward.jsp?';
    const urlParams = `requestid=${requestid}&f_weaver_belongto_userid=${beluserid}&f_weaver_belongto_usertype=0${otherpara}`;
    this.openFullWindowHaveBar(printurl + urlParams);
  }


  openFullWindowHaveBar(url) {
    const width = screen.availWidth - 10;
    const height = screen.availHeight - 50;
    let szFeatures = 'top=0,left=0,';
    szFeatures += `width=${width},`;
    szFeatures += `height=${height},`;
    szFeatures += 'directories=no,status=yes,toolbar=no,location=no,';
    szFeatures += 'menubar=no,scrollbars=yes,resizable=yes';
    window.open(url, '', szFeatures);
  }

  doReadRequest(requestid) {
    WeaTools.callApi('/api/workflow/reqlist/doReadIt', 'POST', { opertype: 'single', requestid }).then(() => {
      this.getTableDatas();
    });
  }

  getColumns = (columns) => {
    let newColumns = columns.map((column) => {
      // if(column.dataIndex == "odoctype"){
      //   return {
      //     ...column, render: (text, record, index) => {
      //       return (<p  class="wea-odoctype-labelp" title={record.odoctypespan}>{record.odoctypespan}</p>);
      //     }
      //   }
      // }else
      if (column.dataIndex == 'wbr') {
        return {
          ...column,
          render: (text, record) => (
            <div id={`${record.requestid}todo`}>
              <span style={{ cursor: 'pointer', textDecoration: 'underline' }} onClick={() => this.getTodo(record.requestid, `${record.requestid}todo`)}>{record.wbrspan}</span>
            </div>
          ),
        };
      } else if (column.dataIndex == 'zbr') {
        return {
          ...column,
          render: (text, record) => (
            <div id={`${record.requestid}doing`}>
              <span style={{ cursor: 'pointer', textDecoration: 'underline' }} onClick={() => this.getDoing(record.requestid, `${record.requestid}doing`)}>{record.zbrspan}</span>
            </div>
          ),
        };
      }
      return column;
    });
    return newColumns;
  }
}

